﻿using Hvam.SharePoint.Search.Query;
using Microsoft.Office.Server.Search.Administration;
using Microsoft.Office.Server.Search.Query;
using Microsoft.SharePoint;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace Hvam.SharePoint.Search.Tests.Public.Query
{
    [TestClass]
    public class LocationExtensionsTests
    {
        [TestMethod]
        public void LocationExtensionsGetSortList()
        {
            // Arrange
            using (var site = new SPSite(TestConstants.Site))
            {
                var serviceContext = SPServiceContext.GetContext(site);

                var searchProxy = (SearchServiceApplicationProxy) serviceContext.GetDefaultProxy(typeof(SearchServiceApplicationProxy));

                var location = new Location("LocalSearchIndex", searchProxy);

                var sortList = location.GetSortList();

                // Act
                sortList.Clear();
                sortList.Add("Title", SortDirection.Descending);

                // Assert
                sortList = location.GetSortList();
                Assert.AreEqual(1, sortList.Count);

                var sort = sortList[0];

                Assert.AreEqual("Title", sort.Property);
                Assert.AreEqual(SortDirection.Descending, sort.Direction);
            }
        }
    }
}
